package com.hk.web.core.config.shiro;

import com.hk.web.core.filter.RestFormAuthenticationFilter;
import com.hk.web.core.filter.RestPermissionsAuthorizationFilter;
import org.apache.shiro.spring.config.web.autoconfigure.ShiroWebFilterConfiguration;
import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;
import java.util.HashMap;
import java.util.Map;

/**
 * 可以添加自定义shiro filter(如果用shirocConfig 继承 会出现循环依赖的错误)
 */
@Configuration
public class ShiroFilterConfig extends ShiroWebFilterConfiguration {


    @Bean
    @ConditionalOnMissingBean
    @Override
    protected ShiroFilterFactoryBean shiroFilterFactoryBean() {
        ShiroFilterFactoryBean shiroFilterFactoryBean = super.shiroFilterFactoryBean();
        Map<String, Filter> filters = new HashMap<>();
        filters.put("authc",new RestFormAuthenticationFilter());
//        filters.put("perms",new RestPermissionsAuthorizationFilter());
        shiroFilterFactoryBean.setFilters(filters);
        return shiroFilterFactoryBean;
    }
}
